import {Component} from '@angular/core';
import * as changeCase from "change-case";
import {DB_JavaType} from '../gencode_constants';
import {Column} from '../../../modules/gencode/GenCodeM';

@Component({
  selector: 'app-jimmer',
  standalone: true,
  imports: [],
  templateUrl: './jimmer.component.html',
  styleUrl: './jimmer.component.less'
})
export class JimmerComponent {

  packages_v: string = 'papapap';
  currentTime: string = new Date().toLocaleString();
  imports: string[] = ['imp'];

  tableInfo = {
    comment: "cccccccxxx",
    tableName: 'ttttttt',
    columns: [
      {
        type: -5,
        comment: '主键的描述',
        isPk: true,
        name: 'column_id',
        isNullable: false,
      },
      {
        type: 12,
        comment: 'co描述',
        isPk: false,
        name: 'column_str',
        isNullable: true,
      }
    ],

  }

  //转换名字的工具类库
  protected readonly changeCase = changeCase;
  //映射map
  protected readonly DB_JavaType = DB_JavaType;

  getColumndatatype(column: Column) {
    const newVar = DB_JavaType.get(column.type);

    var columndatatype: string | undefined = '';
    if (column.isNullable && newVar?.javaTypeNull == newVar?.javaTypeNotNull!) {
      columndatatype = newVar.javaTypeNull;
    } else {
      columndatatype = newVar?.javaTypeNotNull;
    }
    return columndatatype;
  }

  //复制到剪贴板
  copyContent(event: MouseEvent) {
    const target = event.target as HTMLElement;
    const parentElement = target.parentElement;
    // 获取父节点中的第一个 <div>
    const contentElement = parentElement?.querySelector('div');
    const content = contentElement?.innerText || '';
    if (content === null || content === '') {
      alert("没数据")
      return;
    }
    navigator.clipboard.write([
      new ClipboardItem({
        'text/html': new Blob([content], {type: 'text/html'}),
        'text/plain': new Blob([content], {type: 'text/plain'})
      })
    ])
      .then(() => {
        alert('复制成功y!');
      })
      .catch((err) => {
        console.error('Failed to copy content:', err);
        alert('复制失败');
      });
  }

  //下载成文件
}

